cmake_minimum_required(VERSION 4.0)
project(simple-cfd-vis C CXX)

### Setup CPM
set(CPM_DOWNLOAD_VERSION 0.42.0)
set(CPM_HASH_SUM "2020b4fc42dba44817983e06342e682ecfc3d2f484a581f11cc5731fbe4dce8a")

if(CPM_SOURCE_CACHE)
  set(CPM_DOWNLOAD_LOCATION "${CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake")
elseif(DEFINED ENV{CPM_SOURCE_CACHE})
  set(CPM_DOWNLOAD_LOCATION "$ENV{CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake")
else()
  set(CPM_DOWNLOAD_LOCATION "${CMAKE_BINARY_DIR}/cmake/CPM_${CPM_DOWNLOAD_VERSION}.cmake")
endif()

get_filename_component(CPM_DOWNLOAD_LOCATION ${CPM_DOWNLOAD_LOCATION} ABSOLUTE)

file(DOWNLOAD
     https://github.com/cpm-cmake/CPM.cmake/releases/download/v${CPM_DOWNLOAD_VERSION}/CPM.cmake
     ${CPM_DOWNLOAD_LOCATION} EXPECTED_HASH SHA256=${CPM_HASH_SUM}
)

include(${CPM_DOWNLOAD_LOCATION})

### Declare dependencies
CPMAddPackage("gh:fmtlib/fmt#11.1.4")
CPMAddPackage(URI "gh:gabime/spdlog#v1.15.1" OPTIONS "SPDLOG_FMT_EXTERNAL ON")
CPMAddPackage("gh:libsdl-org/SDL#release-3.2.22")
CPMAddPackage(
  NAME imgui
  GIT_REPOSITORY https://github.com/ocornut/imgui.git
  GIT_TAG v1.92.2b
  DOWNLOAD_ONLY YES
)

if (imgui_ADDED)
  FILE(GLOB imgui_sources ${imgui_SOURCE_DIR}/*.cpp)
  list(APPEND imgui_sources ${imgui_SOURCE_DIR}/backends/imgui_impl_sdl3.cpp ${imgui_SOURCE_DIR}/backends/imgui_impl_sdlrenderer3.cpp)
  add_library(imgui STATIC ${imgui_sources})
  target_include_directories(imgui PUBLIC ${imgui_SOURCE_DIR})
  target_link_libraries(imgui PUBLIC SDL3::SDL3)
endif()

find_package(OpenMP REQUIRED)

### Executable
add_executable(simple-cfd-vis src/main.cpp)
target_link_libraries(simple-cfd-vis PUBLIC fmt::fmt spdlog::spdlog SDL3::SDL3 OpenMP::OpenMP_CXX imgui)